<layout name='Layout/layout_main' />
<link type="text/css" href="__PUBLIC__/css/jquery-ui.css" rel="stylesheet"/>
<script type="text/javascript" src="__PUBLIC__/js/jquery-ui.min.js"></script>
<script type="text/javascript">
	function add() {
		window.open("{:U('add')}", "_self");
		return false;
	}

	function edit() {
		id = $("li.tbody.active :checkbox").val();
		if (id == undefined) {
			alert("请选择要编辑的订单");
			return false;
		} else {
			window.open(fix_url("{:U('edit')}?id=" + id), "_self");
		}
	}

	function select_supplier() {
		winopen("{:U('supplier/winpop')}", 600, 400);
	}

	function mark(action) {
		if ($("#form_data .table input:checked").length == 0) {
			$("li.tbody.active input:checkbox").attr("checked", true);
		}
		var vars = $("#form_data").serialize();
		switch(action) {
			case "del":
				if (confirm('确定要删除吗?')) {
					sendAjax("{:U('mark?action=del')}", vars, function(data) {
						alert(data.info);
						if (data.status) {
							$("input[name='material_id[]']:checkbox:checked").each(function() {
								$(this).parents("li").remove();
							})
						}
					});
				}
				break;
			default:
		}
		$("#select_all").attr("checked", false);
	}

	function move_to(val) {
		if ($("#form_data .table input:checked").length == 0) {
			$("li.tbody.active input:checkbox").attr("checked", true);
		}
		var vars = $("#form_data").serialize();
		sendAjax("{:U('mark?action=move_folder')}", 'val=' + val + '&' + vars, function(data) {
			alert(data.info);
			$("#form_data .table input:checked").each(function() {
				class_name = $(".dropdown-menu #" + val).text();
				$(this).parents("li").find("span.class").text(class_name);
			})
			$("li.tbody input:checkbox").attr("checked", false);
		});
	}

	function export_contact() {
		window.open("{:U('export')}", "_blank");
	}

	function import_contact() {
		window.open("{:U('import')}", "_self");
	}

	function total_init() {
		$("li.tbody").each(function() {
			total_qty = 0;
			$(this).find(".data_item .qty").each(function() {
				total_qty = dec_add(total_qty, $(this).text());
			})
			$(this).find(".data_total .qty").text(total_qty);
			total_sum = 0;
			$(this).find(".data_item .sum").each(function() {
				total_sum = dec_add(total_sum, $(this).text());
			})
			$(this).find(".data_total .sum").text(total_sum);
		})
		$("li .qty").each(function() {
			$(this).text(formatQty($(this).text()));
		})
		$("li .price,li .sum").each(function() {
			$(this).text(formatMoney($(this).text()));
		})
	}

	function process(obj, data) {
		li = obj.parents("div.controls");
		li.find("input[name='mat_no']").val(data.mat_no);
	}


	$(document).ready(function() {
		set_return_url();
		total_init();
		$("#start_date").datepicker({
		});
		$("#end_date").datepicker({
		});
		$("#move_to li").click(function() {
			move_to($(this).attr("id"));
		})

		$(".table input:checkbox").click(function(e) {
			$("li.tbody.active").removeClass("active");
			$("li.tbody input:checked").each(function() {
				$(this).parents("li.tbody").addClass("active");
			})
			e.stopPropagation();
		})

		$("li.tbody").click(function() {
			$("li.tbody.active").removeClass("active");
			$(this).addClass("active");
			$(".table input:checkbox").attr("checked", false);
		})
	}); 
</script>
<div class="po">
	<form id="form_search" method='post' >
		<div class="row-fluid title">
			<span>采购订单</span>
			<div class="input-append right">
				<input type="text"  onkeydown="key_search();" name="keyword">
				<a class="btn" type="button" onclick="btn_search();"> <i class="icon-search"></i> </a>
				<a class="btn" onclick="open_search();"> <i class="icon-angle-down"></i> </a>
			</div>
		</div>
		<div class="row-fluid adv_search">
			<div class="row-fluid adv_search_head">
				<h4 class="left">高级搜索</h4>
				<div class="right text-right">
					<a  class="btn" onclick="adv_search();">搜索</a>
					<a  class="btn" onclick="close_search();">关闭</a>
				</div>
			</div>
			<div class="row-fluid form-horizontal">
				<div class="control-group span6">
					<label class="control-label" for="supplier_name">供应商：</label>
					<div class="controls">
						<div class="input-append">
							<input  type="hidden" id="supplier" name="eq_supplier" class="key" >
							<input  type="text" id="supplier_name" name="supplier_name" class="val"  source="{:U('supplier/json')}" >
							<button class="btn" type="button"  onclick="select_supplier()" >
								选择
							</button>
						</div>
						<div class="search dropdown ">
							<ul class="dropdown-menu"></ul>
						</div>
					</div>
				</div>
				<div class="control-group span6">
					<label class="control-label" for="start_date">时间：</label>
					<div class="controls">
						<input  type="text" name="start_date" id="start_date" class="input-date" value="{$start_date}"  readonly="readonly">
						&nbsp;~&nbsp;
						<input type="text" name="end_date" id="end_date" value="{$end_date}" readonly="readonly" class="input-date" >
					</div>
				</div>
			</div>
			<div class="row-fluid form-horizontal">
				<div class="control-group span6">
					<label class="control-label" for="material_name">资材：</label>
					<div class="controls">
						<input type="hidden" name="mat_no" class="key" >
						<input type="text" name="material_name" source="{:U('material/json')}" class="val" key_field="mat_no">
						<div class="search dropdown">
							<ul class="dropdown-menu"></ul>
						</div>
					</div>
				</div>
				<div class="control-group span6">
					<label class="control-label" for="po_no">订单：</label>
					<div class="controls">
						<input  type="text" id="po_no" name="po_no" >
					</div>
				</div>
			</div>
			<div class="row-fluid form-horizontal">
				<div class="control-group span6">
					<label class="control-label" for="type">订单类型：</label>
					<div class="controls">
						<select name="type">
							<option></option>
							<option value="1">采购订单</option>
							<option value="2">直接入库</option>
						</select>
					</div>
				</div>
				<div class="control-group span6">
					<label class="control-label" for="payment">付款方式：</label>
					<div class="controls">
						<select name="payment">
							<option></option>
							<option value="1">预付货款</option>
							<option value="2">预付部分</option>
							<option value="3">货到付款</option>
						</select>
					</div>
				</div>
			</div>
			<div class="row-fluid form-horizontal">
				<div class="control-group span6">
					<label class="control-label" for="user_name">制单：</label>
					<div class="controls">
						<input type="hidden" name="user_id" class="key">
						<input type="text" name="user_name" source="{:U('user/json')}" class="val" check="require" msg="请输入资材编号">
						<div class="search dropdown">
							<ul class="dropdown-menu"></ul>
						</div>
					</div>
				</div>
				<div class="control-group span6">
					<label class="control-label" for="remark">备注：</label>
					<div class="controls">
						<input  type="text" id="remark" name="remark" >
					</div>
				</div>
			</div>
		</div>
	</form>
	<form id="form_data" name="form_data" method='post'>
		<input type="hidden" name="ajax" id="ajax" value="1">
		<div class="operate row-fluid">
			<div class="left">
				<a class="btn" onclick="edit();">编辑</a>
				<a class="btn" onclick="mark('del');">删除</a>
			</div>
			<div class="right">
				<a class="btn" onclick="add();">新建</a>
			</div>
		</div>
		<div class="table">
			<ul>
				<li class="thead">
					<div class="row-fluid">
						<div class="span6" style="padding-left:30px">
							<span style="width:40%" class="checkbox">
								<input  type="checkbox" id="chk_select_all" value="all" onclick="select_all('po_id[]')"/>
								<div class="wrap">
									供应商
								</div> </span>
							<span style="width:30%;">日期</span>
							<span style="width:30%;">订单</span>
						</div>
						<div class="span6 hidden-phone">
							<span style="width:20%;">类型</span>
							<span style="width:20%;">付款方式</span>
							<span style="width:20%;">制单</span>
							<span style="width:20%;">状态</span>
							<span style="width:20%;">备注</span>
						</div>
					</div>
					<div class="row-fluid">
						<div class="span6">
							<span style="width:30%;">编号</span>
							<span style="width:40%;">名称+属性</span>
							<span style="width:15%;">规格</span>
							<span style="width:15%;">单位</span>
						</div>
						<div class="span6">
							<span style="width:20%;" >数量</span>
							<span style="width:20%;" >进价</span>
							<span style="width:20%;" >金额</span>
							<span style="width:40%;" > 备注 <span>
						</div>
					</div>
				</li>
				<if condition="count($list) eq 0 ">
					<li class="tbody text-center">
						<h3>没找到相应的数据</h3>
					</li>
			</ul>
		</div>
	</form>
	<else/>
	<foreach name="list" item="vo">
		<neq name="vo.po_no" value="$list[$key-1]['po_no']">
			<li class="tbody">
				<div class="row-fluid data_head">
					<div class="span6"  style="padding-left:30px">
						<span  class="checkbox">
							<input  type="checkbox" value="all" name="po_id[]"/>
						</span>
						<span style="width:40%">{$vo.supplier_name}</span>
						<span style="width:30%;"  class="text-center">{$vo.po_date}</span>
						<span style="width:30%;"  class="text-center">{$vo.po_no}</span>
					</div>
					<div class="span6 hidden-phone">
						<span style="width:20%;"  class="text-center">&nbsp;{$vo.type}</span>
						<span style="width:20%;"  class="text-center">&nbsp;{$vo.payment}</span>
						<span style="width:20%;"  class="text-center">{$vo.user_name}</span>
						<span style="width:20%;"  class="text-center">关闭</span>
						<span style="width:40%;"  class="text-center">{$vo.remark}</span>
					</div>
				</div>
		</neq>
		<div class="row-fluid data_item">
			<div class="span6" style="padding-left:10px">
				<span style="width:30%;" >{$vo.mat_no}</span>
				<span style="width:40%;" >{$vo.material_name}</span>
				<span style="width:15%;" class="text-center autocut">{$vo.spec}</span>
				<span style="width:15%;" class="text-center autocut">{$vo.unit}</span>
			</div>
			<div class="span6">
				<span style="width:20%;" class="text-right qty">{$vo.qty}</span>
				<span style="width:20%;" class="text-right price">{$vo.price}</span>
				<span style="width:20%;" class="text-right sum">{$vo.sum}</span>
				<span style="width:20%;" class="text-right in_qty">{$vo.in_qty|default="&nbsp;"}</span>
				<span style="width:20%;" class="text-right">{$vo.po_remark}<span>
			</div>
		</div>
		<neq name="vo.po_no" value="$list[$key+1]['po_no']">
			<div class="row-fluid data_total" >
				<div class="span6" style="padding-left:10px">
					<b>合计</b>
				</div>
				<div class="span6">
					<span style="width:20%;" class="text-right qty"></span>
					<span style="width:20%;" class="text-right price">&nbsp;</span>
					<span style="width:20%;" class="text-right sum"></span>
					<span style="width:20%;" class="text-right in_qty"></span>
					<span style="width:20%;" class="text-right"><span>
				</div>
			</div>
			</li>
		</neq>
	</foreach>
	</ul>
</div>
</form>
<div class="page">
	{$page}
</div>
</if>
</div>